var verify = sessionStorage.getItem('verify');
if (verify == "true"){
    location.href="index.html";
}
else if(verify == "false"){
    sessionStorage.setItem('verify',"false");
}
else {
    sessionStorage.setItem('verify',"false");
}

$("body").keyup(function (event) {
    if (event.keyCode == "13") {
        $("#login").click();
    }
});

$("#login").click(function () {
    var account = $('#account').val();
    var psw = $('#psw').val();
    var character = $("input[name = 'character']:checked").val();

    if (account == '') {
        alert('请输入用户名');
        location.reload();
        return false;
    }
    if (psw == '') {
        alert('请输入密码');
        location.reload();
        return false;
    }
    if (character == null) {
        alert('请选择账户类别');
        location.reload();
        return false;
    }
//将数据传到后台
    $.ajax({
        url: '/user?method=login',
        type: 'post',
        data: {account: account, psw: psw, character: character},
        dataType: 'json',
        success: function (result) {
            if (result.verify) {
                var name = result.name;
                var character = result.character;
                sessionStorage.setItem('account', account);
                sessionStorage.setItem('name', name);
                sessionStorage.setItem('verify', 'true');
                sessionStorage.setItem('character', character);

                location.href = "index.html";
            }
            else {
                sessionStorage.setItem('verify', 'false');
                alert('失败');
            }
        }
    });
});